﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using FinosLibrary;
namespace FinosServiceLibrary.Server {
    public class ServerLogic {
        public AppLoader application;
        public void trace(params string[] msg) {
            application.TraceMessage(msg);
        }
        public Client getClientById(string clientId) {
            return application.getClientById(clientId);
        }
        public void call(object clientId,string fun,object obj) {
            call(clientId, new Package(fun, obj));
        }
        public void call(object clientId, string fun) {
            call(clientId, new Package(fun));
        }
        public void call(object clientId, Package p) {
            if (clientId is AdminClient) {
                application.call((clientId as AdminClient).id, Inbox(p));
            } else {
                application.call(clientId as string, p);
            }
        }
        
        private Package Inbox(Package p) {
            return new Package("PropertyPagePackage", new Package(application.name, p));
        }
        public void broadcast(string fun, object obj) {
            application.broadCast(new Package(fun, obj));
        }
        public void broadcast(string fun) {
            application.broadCast(new Package(fun));
        }
        public void broadcast(Package p) {
            application.broadCast(p);
        }
    }
}
